<?php

namespace common\model;

use think\model\RelationModel;

class PlanModel extends RelationModel
{

    const TYPE_TO_DO = 'to_do'; // 待办
    const TYPE_STEP_CATEGORY = 'step_category'; // 工序分类
    const TYPE_EPISODE = 'episode'; // 剧集计划
    const TYPE_MILESTONE = 'milestone'; // 里程碑
    const TYPE_MEETING = 'meeting'; // 会议
    const TYPE_REVIEW = 'review'; // 审核
    const TYPE_CUSTOM = 'custom'; // 自定义

    const SCOPE_SINGLE = 'single'; // 单集
    const SCOPE_GLOBAL = 'global'; // 全局

    const IS_LOCK_YES = 1;   //锁定
    const IS_LOCK_CANCEL = 2;  //取消锁定

    const TYPE_GROUP = [
        self::TYPE_TO_DO, self::TYPE_STEP_CATEGORY, self::TYPE_MILESTONE, self::TYPE_MEETING, self::TYPE_REVIEW, self::TYPE_CUSTOM
    ];

    const TYPE_TODO_GROUP = [
        self::TYPE_TO_DO, self::TYPE_MILESTONE, self::TYPE_MEETING, self::TYPE_REVIEW, self::TYPE_CUSTOM
    ];

    const TYPE_PLAN_SCOPE = [
        'to_do', 'step_category'
    ];

    //自动验证
    protected $_validate = [
        ['project_id', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
        ['step_category_id,project_id', '', '', self::EXISTS_VALIDATE, 'unique'],
        ['start_time', '', '', self::EXISTS_VALIDATE, 'date'],
        ['end_time', '', '', self::EXISTS_VALIDATE, 'date'],
        ['type', ['episode', 'step_category', 'entity', 'entity_step_category', 'to_do', 'milestone', 'meeting', 'review', 'custom'], '', self::EXISTS_VALIDATE, 'in'], // 类型
    ];

    //自动完成
    protected $_auto = [
        ['tenant_id', 'auto_fill_tenant_id', self::MODEL_INSERT, 'function'],
        ['project_id', 'auto_fill_project_id', self::MODEL_INSERT, 'function_with_data'],
        ['start_time', 'strtotime', self::EXISTS_VALIDATE, 'function'],
        ['end_time', 'strtotime', self::EXISTS_VALIDATE, 'function'],
        ['uuid', 'create_uuid', self::MODEL_INSERT, 'function'],
        ['created_by', 'fill_created_by', self::MODEL_INSERT, 'function'],
        ['created', 'time', self::MODEL_INSERT, 'function'],
    ];

    /**
     * 获取器：计划开始时间
     * @param $value
     * @param $data
     * @return array|mixed
     */
//    public function getStartTimeAttr($value, $data)
//    {
//        if (!empty($value)) {
//            return get_format_date($value, 1);
//        }
//        return "";
//    }

    /**
     * 获取器：计划结束时间
     * @param $value
     * @param $data
     * @return array|mixed
     */
//    public function getEndTimeAttr($value, $data)
//    {
//        if (!empty($value)) {
//            return get_format_date($value, 1);
//        }
//        return "";
//    }
}
